#ifndef WIDGET_MANAGER_H
#define WIDGET_MANAGER_H

// add necessary includes here
#include "ui/defines/global.h"

class FormStatusBar;
class FormToolBar;
class FormHome;
class FormSelfCheck;
class FormLogin;

class FormSetting;
class FormSettingMode;
class FormSettingLanguage;
class FormSettingRTC;
class FormSettingNetwork;
class FormSettingLog;
class FormSettingUpgrade;
class FormSettingDataTools;
class FormSettingVersion;

class FormFactory;
class FormHeatingDebug;
class FormMotorDebug;
class FormProcessDebug;
class FormExtractDebug;
class FormUvDisinfection;
class FormFactoryParams;
class FormSelfChecking;
class FormDeviceNotify;

QT_BEGIN_NAMESPACE
namespace Ui { class WidgetManager; }
QT_END_NAMESPACE

class WidgetManager : public QWidget
{
    Q_OBJECT

public:
    WidgetManager(QWidget *parent = nullptr);
    ~WidgetManager();

private slots:
    // Self-test completed
    void slotSelfCheckCompleted(int nErrCode);

    // Show the login window
    void slotShowPageLogin();

    // Show the main window after login
    void slotShowPageHome();


    // Show the setting page after clicked
    void slotShowPageSetting();

    // Show the mode page after clicked menu
    void slotShowPageSetMode();

    // Show the language window after clicked menu
    void slotShowPageSetLanguage();

    // Show RTC setting window after click menu
    void slotShowPageSetRTC();

    // Show the network page after clicked menu
    void slotShowPageSetNetwork();

    // Show the log page after clicked menu
    void slotShowPageSetLog();

    // Show the upgrade page after clicked menu
    void slotShowPageSetUpgrade();

    // Show the data tools window after click menu
    void slotShowPageSetDataTools();

    // Show the version setting window after click menu
    void slotShowPageSetVersion();


    // Show the result list page after clicked
    void slotShowPageResultList();

    // Show the result details page after clicked
    void slotShowPageResultDetails(int nTestId);


    // Show the factory page after clicked
    void slotShowPageFactory();

    // Show the UV disinfection window after click menu
    void slotShowPageUvDisinfection();

    // Show the heating debug window after click menu
    void slotShowPageHeatingDebug();

    // Show the motor debug window after click menu
    void slotShowPageMotorDebug();

    // Show the process debug window after click menu
    void slotShowPageProcessDebug();

    // Show the PCR debug window after click menu
    void slotShowPagePcrDebug();

    // Show the extract window after click menu
    void slotShowPageExtractDebug();

    // Show the Kit list window after click menu
    void slotShowPageKitList();

    // Show the factory params setting window after click menu
    void slotShowPageFactoryParams(int nType);

    // Show the self-checking page after clicked menu
    void slotShowPageSelfChecking();

    // Show the notify setting window after click menu
    void slotShowPageDeviceNotify();


    // Switch the language type
    void slotSwitchLanguage(int eumLangType);

    // Receive a payload data from serialport (error log)
    void slotErrorLogPayload(unsigned int unCanId, int nLevel, int nCoding);

private:
    // After constructing object, initialize the object
    void _initialze();

    // Init the window style
    void _initUi();

    // Hide pages & set the geometry for toolbar & statusbar
    void _pageHideAndGeometry();

    // Load the QSS file for the common control
    void _loadCommonQSS();

    // Load plugins from local
    int _loadPlugins();

    // Unload plugins
    void _unloadPlugins();

    // Initialize interfaces
    int _initInterfaces();

    // Uninitialize interfaces
    void _uninitInterfaces();

    // Switch the language(English/Chinese)
    void _switchLanguage(bool bEnglish = true);

    // Configure language & CAN
    void _configFromINI();

    // Config firmware
    void _configFirmware();

    // Get the window instances
    void _getWindowInstance();

    // Correlation signal and slot function
    void _associateSignalSlot();

private:
    Ui::WidgetManager *ui;

    QList<QWidget *>            m_lstWidgets;
    std::map<QString, QObject*> m_mapInterface;
    QTranslator                 *m_pTrans = nullptr;

    FormStatusBar               *m_pFrmStatusBar = nullptr;
    FormToolBar                 *m_pFrmToolBar = nullptr;
    FormHome                    *m_pFrmHome = nullptr;
    FormSelfCheck                *m_pFrmSelfCheck = nullptr;
    FormLogin                   *m_pFrmLogin = nullptr;

    FormSetting                 *m_pFrmSetting = nullptr;
    FormSettingLanguage         *m_pFrmSetLanguage = nullptr;
    FormSettingRTC              *m_pFrmSetRTC = nullptr;
    FormSettingNetwork          *m_pFrmSetNetwork = nullptr;
    FormSettingLog              *m_pFrmSetLog = nullptr;
    FormSettingUpgrade          *m_pFrmSetUpgrade = nullptr;
    FormSettingDataTools        *m_pFrmSetDataTools = nullptr;
    FormSettingVersion          *m_pFrmSetVersion = nullptr;
    FormSettingMode             *m_pFrmSetMode = nullptr;

    FormFactory                 *m_pFrmFactory = nullptr;
    FormUvDisinfection          *m_pFrmFacUvDisinfection = nullptr;
    FormHeatingDebug            *m_pFrmFacHeatingDebug = nullptr;
    FormMotorDebug              *m_pFrmFacMotorDebug = nullptr;
    FormProcessDebug            *m_pFrmFacProcessDebug = nullptr;
    FormExtractDebug            *m_pFrmFacExtractDebug = nullptr;
    FormFactoryParams           *m_pFrmFacFactoryParams = nullptr;
    FormSelfChecking            *m_pFrmFacSelfChecking = nullptr;
    FormDeviceNotify            *m_pFrmFacDeviceNotify = nullptr;
};
#endif // WIDGET_MANAGER_H
